<?php
class Button{
	var $id;
	var $icons_primary;
	var $icons_secondary;
	var $onClick;
	var $value = "clickMe";
	public function __construct($id=""){
		$this->id = $id;
	}
	public function renderHead(){
		$p  = "$('#".$this->id."').button(";
		if(isset($this->icons_primary))
		$p.="primary:'".$this->icons_primary."',";
		if(isset($this->icons_secondary))
		$p.="primary:'".$this->icons_secondary."'";
		$p.=")\n";
		if(isset($this->onClick))
		$p .= $this->onClick;
		return $p;
	}
	public function renderBody(){
		return "<button id=\"".$this->id."\" >".$this->value."</button>";
	}
	//PUBLIC_ORDER
	
	/**
	 * $icon = @String the icon value of the button available values are ui-icon-*
	 */
	public function setPrimaryIcon($icon){
		$this->icons_primary = $icon;
	}
	
	/**
	 * $icon = @String the icon value of the button available values are ui-icon-*
	 */
	public function setSecondaryIcon($icon){
		$this->icons_secondary = $icon;
	}
	
	public function setClickEvent($body){
		$this->onClick= "$( \"#".$this->id."\").click(function() { ".$body." });";
	}
}
class AnchorButton extends Button{
	var $href;
	public function renderBody(){
		return "<a href=\"".$this->href."\" id=\"".$this->id."\" >".$this->value."</a>";
	}
	public function setHref($anchor){
		$this->href = $anchor;
	}
}
class RadioButton extends Button{
	var $name;
	var $labels;
	public function __construct($id=""){
		parent::__construct($id);
		$this->name = "radio";
		$this->labels = array();
	}
	public function renderHead(){
		$p  = "$('#".$this->id."').buttonset(";
		if(isset($this->icons_primary))
		$p.="primary:'".$this->icons_primary."',";
		if(isset($this->icons_secondary))
		$p.="primary:'".$this->icons_secondary."'";
		$p.=")\n";
		if(isset($this->onClick))
		$p .= $this->onClick;
		return $p;
	}
	public function renderBody(){
		$output = "<div id=\"".$this->id."\">\n";
		$i=1;
		foreach($this->labels as $label)
		{
			$output .= "<input type=\"radio\" id=\"".$this->id.$i."\" name=\"".$this->name."\"/><label for=\"".$this->id.$i."\">".$label."</label>\n";
			$i++;
		}
		$output .= "</div>\n";
		return $output;
	}
	public function addButton($label){
		array_push($this->labels,$label);
	}
	public function setName($name){
		$this->name = $name;
	}
	
	public function getName(){
		return $this->name;
	}
	
}
class CheckButton extends RadioButton{
	public function __construct($id){
		parent::__construct($id);
		$this->name = "check";
	}
	public function renderHead(){
		$p  = "$('#".$this->id."').buttonset(";
		if(isset($this->icons_primary))
		$p.="primary:'".$this->icons_primary."',";
		if(isset($this->icons_secondary))
		$p.="primary:'".$this->icons_secondary."'";
		$p.=")\n";
		if(isset($this->onClick))
		$p .= $this->onClick;
		return $p;
	}
	public function renderBody(){
		$output = "<div id=\"".$this->id."\">\n";
		$i=1;
		foreach($this->labels as $label)
		{
			$output .= "<input type=\"checkbox\" id=\"".$this->id.$i."\" name=\"".$this->name."\"/><label for=\"".$this->id.$i."\">".$label."</label>\n";
			$i++;
		}
		$output .= "</div>\n";
		return $output;
	}
}
